// var getWithdrawalsRecords = "http://localhost:8080/hjcr-wechat/drawrecord/getByUserId";
var getWithdrawalsRecords = "./json/withdrawalsRecords.json";
$(document).ready(function(){
  var page=0;
  var totalPage =0;
  function getRecord(num,size) {
    $.get(getWithdrawalsRecords,{params:{userId:sessionStorage.userId,currentPage:num,size:size}},function (res) {
      if(res.serviceResult){
        var data = res.resultParm.list;
        totalPage = res.resultParm.totalPages;
        var html = "";
        for (var i = 0; i < data.length; i++) {
          var status = "";var statusClass = "";
          switch (data[i].status) {
            case 0:status="处理中";break;
            case 1:status="已提现";statusClass="success";break;
            case 2:status="拒绝申请";statusClass="fail";break;
            default:break;
          }
          var way = "";
          if (data[i].way==1) {
            way="银行卡";
            info = bankName(data[i].card.bank);
            var str = data[i].card.number;
            number = str.substring(str.length-4,str.length);
          }
          else {
            way="支付宝";
            info="账号";
            number = data[i].alipay;
          }
          html +=   '<div class="list-item">'+
                      '<div class="row">'+
                        '<div class="col-14 price">'+
                          '¥'+data[i].money+''+
                        '</div>'+
                        '<div class="col-10">'+
                          '<p class="status '+statusClass+'">'+status+'</p>'+
                          '<p class="time">'+data[i].creatTime+'</p>'+
                        '</div>'+
                      '</div>'+
                      '<div class="meta">'+
                        '提现至'+way+'：'+info+'（'+number+'）'+
                      '</div>'+
                    '</div>';

        }
        $(".records-list").append(html);
      }
    })

  }
  getRecord(0,15);
  $(document).scroll(function() {
    if(document.body.scrollHeight-document.body.scrollTop<=window.screen.availHeight){
      if(i<totalPage-1){
        getRecord(++i,15);
      }
    }
  });
});
